"""
【模板】
模板方法模式(Template Method Pattern)

模板方法模式定义了一个算法骨架，将一些步骤延迟到子类中实现。这个模式使得子类可以不改变一个算法的结构即可重定义该算法的某些步骤。

一个抽象类定义死了调用顺序与抽象方法，就像模板一样，子类只能去改内容
"""
from abc import ABC, abstractmethod


class Algorithm(ABC):
    def process_data(self, data):
        self.load_data(data)
        self.analyze_data()
        self.visualize_data()

    @abstractmethod
    def load_data(self, data):
        pass

    @abstractmethod
    def analyze_data(self):
        pass

    @abstractmethod
    def visualize_data(self):
        pass


class AudioProcessing(Algorithm):
    def load_data(self, data):
        print("Loading audio data...")

    def analyze_data(self):
        print("Analyzing audio data...")

    def visualize_data(self):
        print("Visualizing audio data...")


class ImageProcessing(Algorithm):
    def load_data(self, data):
        print("Loading image data...")

    def analyze_data(self):
        print("Analyzing image data...")

    def visualize_data(self):
        print("Visualizing image data...")


audio_processing = AudioProcessing()
image_processing = ImageProcessing()
audio_processing.process_data("Audio data")
image_processing.process_data("Image data")
"""
Loading audio data...
Analyzing audio data...
Visualizing audio data...
Loading image data...
Analyzing image data...
Visualizing image data...
"""
